home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue30 / construc / INDEXBOB.DPR < prev    next >
Encoding:
Text File  |  1998-01-06  |  4.0 KB  |  148 lines

  1. {$APPTYPE CONSOLE}
  2. uses
  3.   DrBobCGI, DrBobSys, IndexBob;
  4. var
  5.   Keywords,Keyword: ShortString;
  6.   Found,SubSet: TPageSet;
  7.   i: Integer;
  8.  
  9.   function GetNextKeyword: ShortString;
  10.   begin
  11.     if Pos(' ',Keywords) > 0 then
  12.     begin
  13.       Result := Copy(Keywords,1,Pos(' ',Keywords)-1);
  14.       Delete(Keywords,1,Pos(' ',Keywords))
  15.     end
  16.     else
  17.     begin
  18.       Result := Keywords;
  19.       Keywords := ''
  20.     end
  21.   end {GetNextKeyword};
  22.  
  23. var
  24.   f: Text;
  25.   Query: Integer;
  26.   _Or, _Not: Boolean;
  27. begin
  28.   writeln('<H2>IndexBob Search Results</H2>');
  29.   Keywords := Value('Keyword');
  30.   if ValueAsInteger('Book') > 0 then Keywords := 'Book Review and '+Keywords;
  31.   if ValueAsInteger('Tool') > 0 then Keywords := 'Tool Review and '+Keywords;
  32.   { COUNTER }
  33.   Assign(f,'indexbob');
  34.   Reset(f);
  35.   if IOResult = 0 then readln(f,Query)
  36.                   else Query := 0;
  37.   Inc(Query);
  38.   rewrite(f);
  39.   writeln(f,Query);
  40.   close(f);
  41.   if IOResult <> 0 then { skip };
  42.   Assign(f,'indexbob.log');
  43.   Append(f);
  44.   if IOResult <> 0 then Rewrite(f);
  45.   writeln(f,Query:7,': ',Keywords);
  46.   Close(f);
  47.   if IOResult <> 0 then { skip };
  48.   writeln('Search: <B>',Query,'</B> since 1997/11/25<BR>');
  49.   writeln('Keyword: <B>',Keywords,'</B><BR>');
  50.   Keywords := LowerCase(Keywords);
  51.   Found := [0..WebPages-1];
  52.   Query := 0; { no queries performed, yet }
  53.   _Not := False;
  54.   _Or := False;
  55.   if root <> nil then
  56.   repeat
  57.     Keyword := GetNextKeyword;
  58.     if Keyword = 'and' then { skip }
  59.     else
  60.     begin
  61.       if Keyword = 'or' then _Or := True
  62.       else
  63.       begin
  64.         if Keyword = 'not' then _Not := True
  65.         else
  66.         begin
  67.           if Length(Keyword) > 2 then
  68.           begin
  69.             SubSet :=  root.FindKeywordInPages(Keyword);
  70.             if SubSet = [] then
  71.               writeln('<BR>Invalid keyword: <I>',Keyword,'</I>')
  72.             else
  73.             begin
  74.               if _Not then SubSet := [0..WebPages-1] - SubSet;
  75.               _Not := False;
  76.               if _Or then
  77.                 Found := Found + SubSet
  78.               else { and }
  79.                 Found := Found * SubSet;
  80.               Inc(Query)
  81.             end
  82.           end
  83.         end
  84.       end
  85.     end
  86.   until Keywords = '';
  87.   if Query = 0 then Found := []; { no SubSet found }
  88.   writeln('<BR>');
  89.   write('<B>',Pages(Found),'</B> pages found');
  90.   Query := 0;
  91.   Keywords := LowerCase(Value('Keyword'));
  92.   Keyword := GetNextKeyword; { first keyword }
  93.   for i:=0 to WebPages-1 do
  94.   begin
  95.     if (i in Found) then
  96.     begin
  97.       if Titles[i] = '' then
  98.         Found := Found - [i] // skip empty title!!
  99.       else
  100.         if Pos(Keyword,LowerCase(Titles[i])) > 0 then Inc(Query)
  101.     end
  102.   end;
  103.   if Query > 0 then write('<B> (',Query,' hot)</B>');
  104.   writeln(':');
  105.   writeln('<UL>');
  106.   if Query > 0 then
  107.   begin
  108.     for i:=0 to WebPages-1 do
  109.     begin
  110.       if (i in Found) and (Pos(Keyword,LowerCase(Titles[i])) > 0) then
  111.       begin
  112.         writeln('<IMG SRC="/gif/arrow.gif"> <B>',Titles[i],'</B>');
  113.         write('<BR><IMG SRC="/gif/backblue.gif"HEIGHT="1"WIDTH=24><A HREF="',WebPage[i]);
  114.         if Pos('(index)',Titles[i]) > 0 then write('"TARGET="_top');
  115.         writeln('">',WebPage[i],'</A>');
  116.         if Query < 7 then writeln('<P>')
  117.                      else writeln('<BR>');
  118.         Found := Found - [i]
  119.       end
  120.     end;
  121.     writeln('<HR><P>')
  122.  
  123.   end;
  124.   if Found <> [] then
  125.   begin
  126.     for i:=0 to WebPages-1 do
  127.     begin
  128.       if i in Found then
  129.       begin
  130.         writeln('<IMG SRC="/gif/arrow.gif"> ',Titles[i]);
  131.         write('<BR><IMG SRC="/gif/backblue.gif"HEIGHT="1"WIDTH=24><A HREF="',WebPage[i]);
  132.         if Pos('(index)',Titles[i]) > 0 then write('"TARGET="_top');
  133.         writeln('">',WebPage[i],'</A><BR>')
  134.       end
  135.     end
  136.   end;
  137.   writeln('</UL>');
  138. {$IFDEF DEBUG}
  139.   writeln('<HR>');
  140.   writeln('<B>Not found:</B>');
  141.   writeln('<UL>');
  142.   for i:=0 to WebPages-1 do
  143.     if not (i in Found) then
  144.       writeln('<LI><A HREF="',WebPage[i],'">',WebPage[i],'</A>');
  145.   writeln('</UL>')
  146. {$ENDIF}
  147. end.
  148.